/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.widget.admin;

import java.util.ArrayList;

import sw6.digipecs.exceptions.ImageIsEmptyException;
import sw6.digipecs.model.ExtImage;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class SelectableExtImageAdapter<T extends ExtImage> extends BaseAdapter {

	public final static int SELECT_MODE_ADD=1; 
	public final static int SELECT_MODE_DELETE = 2; 
	public final static int SELECT_MODE_ACTIVE = 3; 
	
	private Context mContext;
	private ArrayList<T> mImageList;
	private int mSelectMode=0; 
	
	public SelectableExtImageAdapter(Context context, ArrayList<T> images, int selectmode) {
		mContext = context; 
		mImageList = images;
        mSelectMode=selectmode; 
	}
	
	@Override
	public int getCount() {
		return mImageList.size(); 
	}

	@Override
	public ExtImage getItem(int arg0) {
		return mImageList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		try {
			return mImageList.get(arg0).getId();
		} catch (ImageIsEmptyException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		ExtImage image = mImageList.get(position); 
		SelectableExtImageView mImageView; 
		if(convertView==null)
			mImageView=new SelectableExtImageView(mContext); 
		else 
			mImageView = (SelectableExtImageView)convertView; 
		mImageView.setExtImage(image,mSelectMode);
		return mImageView; 
	}

}
